﻿﻿//======================================================================
//
//        Copyright : Zhengzhou Strawberry Computer Technology Co.,LTD.
//        All rights reserved
//        
//        Application:NRapid MVC framework
//        Filename :Controller.cs
//        Description :控制器

//
//        created by Lucas at  2015-6-30`
//     
//        WebSite:http://www.NRapid.com
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
namespace WebApp.App
{
    //Controller基类
    public class Controller : NRapid.BaseAction
    {
        /// <summary>
        /// 网站ID
        /// </summary>
        public int siteId = 1;
        /// <summary>
        /// 网站全局配置
        /// </summary>
        public Code.Cms.Config config = null;
        /// <summary>
        /// 网站数据
        /// </summary>
        public Models.Entity.Common.site site = null;
        /// <summary>
        /// 频道数据
        /// </summary>
        public Models.Entity.Common.channel channel = null;
        public override void Before()
        {
            Code.Cms.Site site = new Code.Cms.Site();
            this.site = site.GetSite(this._subdomain);
            this.config = new Code.Cms.Config();
            base.Before();
        }
        public Controller() { }
        public Controller(string fileName)
            : base(fileName)
        {
        }
        public Controller(TextWriter tw)
            : base(tw)
        {
        }
        public Controller(Controller controller):base(controller)
        {
            controller.config = this.config;
            controller.site = this.site;
            controller.channel = this.channel;
        }
        public Controller(NRapid.Owin.HtmlWriter writer,IDictionary<string,string> cookies):base(writer)
        {
            Cookie = new Code.Data.CookieManager(writer,cookies);
            Session = new Code.Data.SessionManager(writer,cookies);
        }
        public void Error(string msg, string url, int second)
        {
            Web.Default.Common.Public.ErrorAction errorAction = new Web.Default.Common.Public.ErrorAction(_tw);
            errorAction.Error(msg, url, second);
        }
        public void Success(string msg, string url, int second)
        {
            Web.Default.Common.Public.SuccessAction successAction = new Web.Default.Common.Public.SuccessAction(_tw);
            successAction.Success(msg, url, second);
        }
        public void AjaxReturn<T>(List<T> obj)
        {
            this.AjaxReturn(obj.ToJson(), obj!=null && obj.Count>0  ? 1 : 0);
        }
        public Code.Data.CookieManager Cookie = new Code.Data.CookieManager();
        public Code.Data.SessionManager Session = new Code.Data.SessionManager();
    }
}